// packageI/lawyerPlatform/order/order.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    show: true,
    order_type: "",
    last_page: "",
    current_page: 1,
    listData: [],
    httpUrl:"",
    id:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function ({order_type}){
    if (order_type) {
      this.setData({
        order_type
      })
      if (order_type == "lawyer") {
        this.setData({
          httpUrl: "plugin.lawyer-platform.frontend.controllers.order.lawyerOrder"
        })
      } else if (order_type == "member") {
        this.setData({
          httpUrl: "plugin.lawyer-platform.frontend.controllers.order.selfOrder"
        })
      } else if (order_type == "office") {
        this.setData({
          httpUrl: "plugin.lawyer-platform.frontend.controllers.order.lawyerFirmOrder"
        })
      }
    }
    this.getdata()
  },
  getdata() {
    app._postNetWork({
      url: app.getNetAddresss(this.data.httpUrl),
      success: (res) => {
        if (res.data.result == 1) {
          res.data.data.list.data.forEach(item => {
            item.flag = false;
          })
          this.setData({
            listData: res.data.data.list.data,
            last_page: res.data.data.list.last_page
          })
        } else {
          app.tips(res.data.msg)
        }
      }
    })
  },
  goodDetail(e) {
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/packageA/detail_v2/detail_v2?id='+id
    });
  },
  link(e) {
    wx.navigateTo({
      url: '/packageI/lawyerPlatform/detail/detail?type_name=lawyer&id='+e.currentTarget.dataset.id,
    })
  },
  tel(e) {
    let mobile = e.currentTarget.dataset.mobile,
    type = e.currentTarget.dataset.type,
    info = e.currentTarget.dataset.info;
    if(type == 'tel'){
      wx.makePhoneCall({
        phoneNumber: mobile
      })
    }else{
      // wx.navigateTo({
      //   url: '/packageH/chitchat/chatWindow/chatWindow?chatType=1&message_type=1&employeeId='+info.lawyer.employee_id+'&plugin_name=lawyer&'+'user_id='+info.member_id,
      // });
      wx.navigateTo({
        url: '/packageH/chitchat/chatWindow/chatWindow?chatType=1&message_type=1&employeeId='+info.lawyer.employee_id+'&plugin_name=lawyer&'+'user_id='+info.member_id,
      });
    }
  },
  buttonSwitch(e) {
    let id = e.currentTarget.dataset.id;
    if(this.data.id == id){
      this.setData({id:""})
    }else{
      this.setData({id})
    }
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.current_page < this.data.last_page) {
        let url = app.getNetAddresss(this.data.httpUrl),
        page=this.data.page+1;
        app._postNetWork({
          url,
          data: {page},
          success: (res) => {
            if (res.data.result == 1) {
              this.data.listData = this.data.listData.concat(res.data.data.list.data)
              this.setData({
                listData: this.data.listData,
                current_page: res.data.data.list.current_page,
                last_page: res.data.data.list.last_page
              })
            }
          }
        })

    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})